package com.zhglxt.activiti.entity;

import com.zhglxt.common.core.entity.BaseActDto;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;

import java.util.Date;

/**
 * 流程实体数据对象
 * @author liuwy
 */
public class ProcessDefinitionDto extends BaseActDto {

    private static final long serialVersionUID = -2072016053699626229L;
    /**
     * 流程编号
     */
    private String processId;

    /**
     * 流程实例ID
     */
   private String processInstanceId;
    /**
     * 流程名称
     */
    private String name;

    /**
     * 部署编号
     */
    private String deploymentId;
    /**
     * 流程实例当前环节
     */
    private String activitiId;
    /**
     * 流程部署时间
     */
    private Date deploymentTime;
    // 流程运行业务发起时间
    private Date processInstanceStartTime;

    public Date getProcessInstanceStartTime() {
        return processInstanceStartTime;
    }

    public void setProcessInstanceStartTime(Date processInstanceStartTime) {
        this.processInstanceStartTime = processInstanceStartTime;
    }

    /**
     * 流程运行业务key
     */
    private String businessKey;

    /**
     * 流程实例父Id
     */
   private String parentId;

    /**
     * 流程命名空间（该编号就是流程文件targetNamespace的属性值）
     */
    private String category;

    /**
     * 流程编号（该编号就是流程文件process元素的id属性值）
     */
    private String key;

    /**
     * 资源文件名称
     */
    private String resourceName;

    /**
     * 图片资源文件名称
     */
    private String diagramResourceName;

    /**
     * 版本号
     */
    private int version;

    /**
     * 流程是否挂起
     */
    private Boolean suspended;


    private Boolean latest;
    /**
     * 流程定义人ID
     */
    private String tenantId;

    /**
     * 流程发起人
     */
    private String startableByUser;

    /**
     * 流程描述信息
     */
    private String description;

    public ProcessDefinitionDto(Deployment processDefinition) {
        this.setProcessId(processDefinition.getId());
        this.name = processDefinition.getName();
    }


    public ProcessDefinitionDto(ProcessInstance processInstance){

        // 流程部署ID
        this.deploymentId = processInstance.getDeploymentId();
        // 流程ID
        this.processId=processInstance.getProcessDefinitionId();
        // 流程名称
        this.name=processInstance.getProcessDefinitionName();
        // 流程key
        this.key=processInstance.getProcessDefinitionKey();
        // 流程运行实例ID
        this.processInstanceId=processInstance.getProcessInstanceId();
        // 流程运行业务key
        this.businessKey=processInstance.getBusinessKey();
        // 流程实例父Id
        this.parentId=processInstance.getParentId();
        // 流程实例当前环节
        this.activitiId=processInstance.getActivityId();
        // 流程定义所欲人
        this.tenantId=processInstance.getTenantId();
        // 流程定义版本
        this.version = processInstance.getProcessDefinitionVersion();
        // 流程描述
        this.description = processInstance.getDescription();
        // 流程是否挂起
        this.suspended = processInstance.isSuspended();



    }

    public ProcessDefinitionDto(ProcessDefinition processDefinition) {
        this.setProcessId(processDefinition.getId());
        this.name = processDefinition.getName();
        this.deploymentId = processDefinition.getDeploymentId();
        this.category = processDefinition.getCategory();
        this.key = processDefinition.getKey();
        this.resourceName = processDefinition.getResourceName();
        this.diagramResourceName = processDefinition.getDiagramResourceName();
        this.version = processDefinition.getVersion();
        this.description = processDefinition.getDescription();
        this.suspended = processDefinition.isSuspended();
        this.tenantId = processDefinition.getTenantId();
        this.description = processDefinition.getDescription();
    }

    public ProcessDefinitionDto() {

    }

    public String getProcessId() {
        return processId;
    }

    public void setProcessId(String processId) {
        this.processId = processId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDeploymentId() {
        return deploymentId;
    }

    public void setDeploymentId(String deploymentId) {
        this.deploymentId = deploymentId;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getResourceName() {
        return resourceName;
    }

    public void setResourceName(String resourceName) {
        this.resourceName = resourceName;
    }

    public String getDiagramResourceName() {
        return diagramResourceName;
    }

    public void setDiagramResourceName(String diagramResourceName) {
        this.diagramResourceName = diagramResourceName;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public Boolean getSuspended() {
        return suspended;
    }

    public void setSuspended(Boolean suspended) {
        this.suspended = suspended;
    }

    public Boolean getLatest() {
        return latest;
    }

    public void setLatest(Boolean latest) {
        this.latest = latest;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public String getStartableByUser() {
        return startableByUser;
    }

    public void setStartableByUser(String startableByUser) {
        this.startableByUser = startableByUser;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getDeploymentTime() {
        return deploymentTime;
    }

    public void setDeploymentTime(Date deploymentTime) {
        this.deploymentTime = deploymentTime;
    }

    public String getProcessInstanceId() {
        return processInstanceId;
    }

    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    public String getActivitiId() {
        return activitiId;
    }

    public void setActivitiId(String activitiId) {
        this.activitiId = activitiId;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @Override
    public String toString() {
        return "ProcessDefinitionDto{" +
                "processId='" + processId + '\'' +
                ", processInstanceId='" + processInstanceId + '\'' +
                ", name='" + name + '\'' +
                ", deploymentId='" + deploymentId + '\'' +
                ", activitiId='" + activitiId + '\'' +
                ", deploymentTime=" + deploymentTime +
                ", processInstanceStartTime=" + processInstanceStartTime +
                ", businessKey='" + businessKey + '\'' +
                ", parentId='" + parentId + '\'' +
                ", category='" + category + '\'' +
                ", key='" + key + '\'' +
                ", resourceName='" + resourceName + '\'' +
                ", diagramResourceName='" + diagramResourceName + '\'' +
                ", version=" + version +
                ", suspended=" + suspended +
                ", latest=" + latest +
                ", tenantId='" + tenantId + '\'' +
                ", startableByUser='" + startableByUser + '\'' +
                ", description='" + description + '\'' +
                '}';
    }
}
